<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增药企管理')" />
    <th:block th:include="include :: datetimepicker-css"/>
    <th:block th:include="include :: bootstrap-fileinput-css"/>
    <th:block th:include="include :: jquery-smartwizard-css"/>
    <th:block th:include="include :: select2-css"/>
    <th:block th:include="include :: bootstrap-select-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-enterprise-edit" th:object="${enterprise}">
        <input name="id" th:field="*{id}" type="hidden">
        <div class="form-group">
            <label class="col-sm-2 control-label">国家名称</label>
            <div class="col-sm-10">
                <select class="form-control m-b" name="countryId" required id="countryId"
                        th:with="type=${@commonService.countryKeyAndValue()}" data-placeholder="请选择国家名称"
                        th:field="*{countryId}"
                        lay-search="">
                    <option value="">请选择国家名称</option>
                    <option th:each="dict : ${type}" th:text="${dict.vals}"
                            th:value="${dict.keyName}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">药企名称</label>
            <div class="col-sm-10">
                <input name="name" th:value="*{name}" class="form-control" placeholder="请输入药企名称" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">药企英文名称</label>
            <div class="col-sm-10">
                <input name="englishName" th:value="*{englishName}" class="form-control" placeholder="请输入药企英文名称" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">药厂管理</label>
            <div class="col-sm-10">
                <select name="factoryId" class="form-control m-b" th:with="type=${@dict.getType('drug_factory')}">
                    <option value="">请选择药厂</option>
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{factoryId}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-12">
                <label class="col-sm-2 control-label">封面图</label>
                <div class="col-sm-10">
                    <input type="hidden" th:value="*{icon}" name="icon">
                    <div class="file-loading">
                        <input class="form-control file-upload" id="icon" name="file" type="file">
                    </div>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">药企简介</label>
            <div class="col-sm-10">
                <input type="hidden" class="form-control" required>
                <script id="introduce" name="introduce" type="text/plain"></script>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">药企详细内容</label>
            <div class="col-sm-10">
                <input type="hidden" class="form-control" required>
                <script id="detail" name="detail" type="text/plain"></script>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">标题</label>
            <div class="col-sm-10">
                <input name="title" th:value="*{title}" class="form-control" placeholder="请输入标题" type="text">
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label">关键词</label>
            <div class="col-sm-10">
                <input name="keyword" th:value="*{keyword}" class="form-control" placeholder="请输入关键词" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">描述</label>
            <div class="col-sm-10">
                <input name="description" th:value="*{description}" class="form-control" placeholder="请输入描述" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">说明</label>
            <div class="col-sm-10">
                <input name="illustrate" th:value="*{illustrate}" class="form-control" placeholder="请输入说明" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">内容</label>
            <div class="col-sm-10">
                <input type="hidden" class="form-control" required>
                <script id="content" name="content" type="text/plain"></script>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: datetimepicker-js"/>
<th:block th:include="include :: bootstrap-fileinput-js"/>
<th:block th:include="include :: jquery-smartwizard-js"/>
<th:block th:include="include :: select2-js"/>
<th:block th:include="include :: bootstrap-select-js"/>
<script src="/ueditor/ueditor.config.js" type="text/javascript" charSet="utf-8"></script>
<script src="/ueditor/ueditor.all.js" type="text/javascript" charSet="utf-8"></script>
<script src="/ueditor/lang/zh-cn/zh-cn.js" type="text/javascript" charSet="utf-8"></script>

<script th:inline="javascript">
    var prefix = ctx + "ydz/enterprise"
    $("#form-enterprise-edit").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/edit", $('#form-enterprise-edit').serialize());
        }
    }

    $(function() {
        parent.$('body').find('.layui-layer-max:not(.layui-layer-maxmin)').click()

    });

    $(".file-upload").each(function (i) {
        var val = $("input[name='" + this.id + "']").val()
        if (val==""){
            $(".file-upload").fileinput({
                uploadUrl: ctx + 'common/upload',
                maxFileCount: 1,
                autoReplace: true
            }).on('fileuploaded', function (event, data, previewId, index) {
                $("input[name='" + event.currentTarget.id + "']").val(data.response.fileName)
            }).on('fileremoved', function (event, id, index) {
                $("input[name='" + event.currentTarget.id + "']").val('')
            })
        }else{
            $(this).fileinput({
                'uploadUrl': ctx + 'common/upload',
                initialPreviewAsData: true,
                initialPreview: [val],
                maxFileCount: 1,
                autoReplace: true
            }).on('fileuploaded', function (event, data, previewId, index) {
                $("input[name='" + event.currentTarget.id + "']").val(data.response.fileName)
            }).on('fileremoved', function (event, id, index) {
                $("input[name='" + event.currentTarget.id + "']").val('')
            })
            $(this).fileinput('_initFileActions');
        }
    });


    //富文本
    UE.Editor.prototype._bkGetActionUrl = UE.Editor.prototype.getActionUrl;
    UE.Editor.prototype.getActionUrl = function (action) {
        if (action == 'uploadimage' || action == 'uploadscrawl') {
            return '/common/upload';
        } else {
            return this._bkGetActionUrl.call(this, action);
        }
    }
    var ue = UE.getEditor('content', {
        autoHeightEnabled: false,//是否自动长高
        autoFloatEnabled: true,//是否保持toolbar的位置不动
        scaleEnabled: true,//是否可以拉伸长高
        initialFrameWidth: 'auto',//初始化编辑器宽度
        initialFrameHeight: 300,//初始化编辑器高度
    });
    ue.ready(function () {
        ue.execCommand("insertHtml", [[${enterprise}]].content);//富文本回显
    })

    var introduce = UE.getEditor('introduce', {
        autoHeightEnabled: false,//是否自动长高
        autoFloatEnabled: true,//是否保持toolbar的位置不动
        scaleEnabled: true,//是否可以拉伸长高
        initialFrameWidth: 'auto',//初始化编辑器宽度
        initialFrameHeight: 300,//初始化编辑器高度
    });
    introduce.ready(function () {
        introduce.execCommand("insertHtml", [[${enterprise}]].introduce);//富文本回显
    })

    var detail = UE.getEditor('detail', {
        autoHeightEnabled: false,//是否自动长高
        autoFloatEnabled: true,//是否保持toolbar的位置不动
        scaleEnabled: true,//是否可以拉伸长高
        initialFrameWidth: 'auto',//初始化编辑器宽度
        initialFrameHeight: 300,//初始化编辑器高度
    });
    detail.ready(function () {
        detail.execCommand("insertHtml", [[${enterprise}]].detail);//富文本回显
    })
</script>
</body>
</html>